package cn.xshi.sys.service.impl;
import java.util.List;
import java.util.Map;
import cn.xshi.sys.dao.SysMessageDao;
import cn.xshi.sys.form.SysMessageForm;
import cn.xshi.sys.model.SysMessage;
import cn.xshi.sys.service.SysMessageService;
import org.springframework.stereotype.Service;
import cn.xshi.common.base.BaseService;
import cn.xshi.common.util.ExceptionUtil;
import javax.annotation.Resource;
/**
 * @Desc 短消息
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@Service
public class SysMessageServiceImpl extends BaseService implements SysMessageService {

	@Resource
	private SysMessageDao sysMessageDao;

	/**
	 * 分页
	 * @param sysMessageForm
	 * @return
	 */
	public List<SysMessage> getSysMessageListByCondition(SysMessageForm sysMessageForm){
		try{
			return sysMessageDao.getSysMessageListByCondition(sysMessageForm);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}

	/**
	 * 查询对象
	 * @param id
	 * @return
	 */
	public SysMessage getSysMessageById(String id){
		try{
			return sysMessageDao.getSysMessageById(id);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}

	/**
	 * 添加
	 * @param sysMessage
	 * @return
	 */
	public int addSysMessage(SysMessage sysMessage){
		int i = 0;
		try {
			sysMessage.setCreateId(getCurrentAccountId());
			sysMessage.setCreateTime(getDate());
			i = sysMessageDao.addSysMessage(sysMessage);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 修改
	 * @param sysMessage
	 * @return
	 */
	public int updateSysMessage(SysMessage sysMessage){
		int i = 0;
		try {
			sysMessage.setUpdateId(getCurrentAccountId());
			sysMessage.setUpdateTime(getDate());
			i = sysMessageDao.updateSysMessage(sysMessage);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 删除
	 * @param condition
	 * @return
	 */
	public int delSysMessage(Map<String,Object> condition){
		int i = 0;
		try {
			i = sysMessageDao.delSysMessage(condition);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 批量添加
	 * @param sysMessageList
	 * @return
	 */
	public int addBatchSysMessage(List<SysMessage> sysMessageList){
		int i = 0;
		try {
			i = sysMessageDao.addBatchSysMessage(sysMessageList);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 批量修改
	 * @param sysMessageList
	 * @return
	 */
	public int updateBatchSysMessage(List<SysMessage> sysMessageList){
		int i = 0;
		try {
			i = sysMessageDao.updateBatchSysMessage(sysMessageList);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 更新已读状态
	 * @param condition
	 * @return
	 */
	public int updateRead(Map<String,Object> condition){
		int i = 0;
		try {
			i = sysMessageDao.updateRead(condition);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 统计
	 * @param sysMessageForm
	 * @return
	 */
	public List<SysMessage> getSysMessageCountByCondition(SysMessageForm sysMessageForm){
		try{
			return sysMessageDao.getSysMessageCountByCondition(sysMessageForm);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}
}
